package com.bifrost.repository;

import com.bifrost.entity.CouponGrantAuto;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * @author rangf
 * @date 2018/6/15
 */
public interface CouponGrantAutoRepository extends JpaRepository<CouponGrantAuto, Long> {
    List<CouponGrantAuto> findAllBySuccess(Boolean success);

    List<CouponGrantAuto> findAllBySuccess(Boolean success, Pageable request);

    @Query(nativeQuery = true, value = "SELECT * FROM COUPON_GRANT_AUTO where IS_SUCCESS=?1 AND CUSTOMER_PHONE=?2 AND MERCHANT_NUMBER=?3 AND COUPON_ID=?4 LIMIT 1;")
    CouponGrantAuto findFirstByVarious(Boolean success, String phone , String storeCode ,Long couponId );
}
